
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="__ROOT__/Public/Js/jquery-1.5.0.min.js"></script>
    <script type="text/javascript" src="__ROOT__/Public/Js/core.js"></script>
    <title>无标题文档</title>
  </head>

  <body>
    <h1>高级检索</h1>
    <form action="__URL__/search/" method="post" id="frmSearch">
      <table width="900">
        <tbody>
          <tr><td width="60"></td><td>请查找类型：
              <select name="classify">
                <option value="1">行业</option>
                <option value="2">专业</option>
                <option value="3">地区</option>
                <option value="4">法规类型</option>
              </select></td></tr>
          <tr>
            <td width="60">　　</td>
            <td width="881"><div id="LawSection" align="left">
                <table cellspacing="0" cellpadding="0" width="503" border="0">
                  <tbody>
                    <tr><td width="82" height="32">在</td><td width="95" height="32">标题</td><td width="51" height="32">中检索</td>
                      <td width="275" height="32"><input maxlength="50" size="36" name="ltitle_search" /></td>
                    </tr>
                    <tr>
                      <td width="82" height="32">
                        <select size="1" name="condition1">
                          <option value="and" selected="selected">并且</option>
                          <option value="or">或者</option>
                          <option value="not">不包括</option>
                        </select>
                      </td>
                      <td width="95" height="32">全文</td>
                      <td width="51" height="32">中检索</td>
                      <td width="275" height="32"><input maxlength="50" size="36" name="lcontent_search" /></td>
                    </tr>
                    <tr>
                      <td width="82" height="32">
                        <select size="1" name="condition2">
                          <option value="and" selected="selected">并且</option>
                          <option value="or">或者</option>
                          <option value="not">不包括</option>
                        </select>
                      </td>
                      <td width="95" height="32">颁布单位</td>
                      <td width="51" height="32">中检索</td>
                      <td width="275" height="32"><input maxlength="50" size="36" name="luser_search" /></td>
                    </tr>
                    <tr>
                      <td width="82" height="32">
                        <select size="1" name="condition3">
                          <option value="and" selected="selected">并且</option>
                          <option value="or">或者</option>
                          <option value="not">不包括</option>
                        </select>
                      </td>
                      <td width="95" height="32">文号</td>
                      <td width="51" height="32">中检索</td>
                      <td width="275" height="32"><input maxlength="50" size="36" name="lnumber_search" /></td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <div><span style="color:red">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(多个关键字用||分开)</span></div>
              <div id="GJFGDiv" align="left"></div>
              <div id="DFFGDiv" align="left">
                <input type="button" value="检 索" onclick="onSearch()"/>
                <input type="reset" value="清 除" />
                <br />
                <br />
              </div>
              <div id="CPWSSection" align="left"></div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
    检索结果<br />
    <div id="divLoading" style="display: none"><img src="__ROOT__/Public/images/loading.gif" /></div>
    <div id="divList"></div>
    <div id="divPage"></div>

    <script>
      onSearch(0);
      var ids = [], lids = [],cids = [];//记录对应的id数组，用户选择的记录对应id数组，分类1级菜单的id数组
      function onSearch(p){
        $("#divLoading").show();
        var url = '__URL__/search/page/'+p;
        $("#frmSearch").attr("action",url);
        ajax.sendForm("frmSearch", function(obj){
          ids = [];
          var data = obj.data.list;
          var page = obj.data.page;
          var size = obj.data.size;
          var count = obj.data.count;
          var classify = obj.data.classify;
          var classifyID = obj.data.classify_id;
          var str = [], p = 0;
          str[p++] = '<table cellpadding="0" width="100%" ><tbody><tr bgcolor="#0099e3"><th> </th><th>序号</th><th>编号</th><th>法规标题<font color="#FF0000">（点击可查看全文）</font></th><th>颁布单位</th><th>发文号</th><th>颁布时间</th></tr>';
          for (var i = 0; i < data.length; i++) {
            var l = data[i];
            var index = (page*1-1)*size+1;
            ids.push(l.id);
            str[p++] = '<tr><td><input type="checkbox" onclick="clickCheckLaw(this)" value="'+l.id+'" /></td>';
            str[p++] = '<td align="center">'+(index+i)+'</td>';
            str[p++] = '<td>'+l.id+'</td>';
            str[p++] = '<td><a href="__URL__/content/id/'+l.id+'" target="content">'+l.ltitle+'</a></td>';
            str[p++] = '<td>'+l.luser+'</td>';
            str[p++] = '<td>'+l.lnumber+'</td>';
            str[p++] = '<td>'+l.ldate_pub+'</td></tr>';
          }
          str[p++] = '<tr><td colspan=7>';
          str[p++] = '<a href="javascript:void(0)" onclick="clickChcekFoot(this,1)">全选</a>|';
          str[p++] = '<a href="javascript:void(0)" onclick="clickChcekFoot(this,2)">不选</a>|';
          str[p++] = '<a href="javascript:void(0)" onclick="clickChcekFoot(this,3)">反选</a>|';
          str[p++] = '<input type="button" value="删除" onclick="clickDelete()">';
          str[p++] = '<select id="selClassify">';
          if (classifyID == "lawtype_id") {
            for (var i = 0; i < classify.length; i++) {
              var c = classify[i];
              str[p++] = '<option value='+c.id+'>'+c.title+'</option>';
            }
          }else {
            for (var i = 0; i < classify.length; i++) {
              var c = classify[i];
              cids.push(c.id);
              str[p++] = '<option value='+c.id+' style="color:#FF0000">'+c.title+'||</option>';
              for (var j = 0; j < c.downLine.length; j++) {
                str[p++] ='<option value='+c.downLine[j].id+'>'+c.downLine[j].title+'</option>';
              }
            }
          }

          str[p++] = '</select>';
          str[p++] = '<input type="button" value="录入" onclick="clickInsert(\''+classifyID+'\')"/><span style="color:#FF0000">（注意不要选择红色选项）</span>';
          str[p++] = '</td></tr>';
          str[p++] = '</tbody></table>'
          replaceHtml("divList", str.join(''));
          $("#divLoading").hide();
          $("#divPage").html(__foot.html(page,size,count,onSearch));
        });
      }
      
      function clickCheckLaw(self){
        var id = $(self).val();
        if ($(self).attr("checked")) lids.push(id);
        else {
          for (var i = lids.length - 1; i >= 0 ; i--) {
            if (lids[i] == id) lids.splice(i,1);
          }
        }
      }

      function clickChcekFoot(self,type){
        if (type == 1) {
          $(self).parent().parent().parent().find('input[type=checkbox]').attr("checked",true);
          lids = ids;
        }else if(type == 2){
          $(self).parent().parent().parent().find('input[type=checkbox]').attr("checked",false);
          lids = [];
        }else {
          $(self).parent().parent().parent().find('input[type=checkbox]').each(function(i,self){
            if ($(self).attr('checked')) $(self).attr('checked',false);
            else $(self).attr('checked',true);
            clickCheckLaw(self);
          });
        }
      }

      function clickInsert(classifyID){
        var cid = $("#selClassify").val();
        if (lids.length == 0) {
          alert("至少选择一条记录，请选择！");
          return ;
        }
        if (classifyID != "lawtype_id") {
          for (var i = 0; i < cids.length; i++) {
            if (cids[i] == cid) {
              alert("请选择红色以外的分类作为录入!");
              return;
            }
          }
        }
        var data = {"cid":cid,"lids":lids,classify_id:classifyID};
        ajax.send("__URL__/classifyInsert",data,function(obj){
          onSearch();
          lids = [];
        }); 
      }

      function clickDelete(){
        if (lids.length == 0) {
          alert("至少选择一条记录，请选择！");
          return ;
        }
        var data = {lids:lids};
        ajax.send("__URL__/classifyDelete",data,function(obj){
          onSearch();
          lids = [];
        });
      }
    </script>
  </body>
</html>
